[

]// var bookData = dataOne().bookData;
// console.log(bookData)

$(function() {

  // 畅销书排行榜获取高度
  var conH = $(".aside-left .top .con-wrap").height();
  $(".aside-left .top .con").css("height", conH + "px");

  var rankH = $(".con li:nth-child(2) .book-rank").height();
  var rankShowH = 3.5 * rankH;
  var overHiddenH = rankH * 5 + rankShowH;
  $(".book-show").css("height", rankShowH + "px");

  var curBookRank = $(".aside-left li.active .book-rank");
  curBookRank.css("height", rankH + "px");


  var base = "http://localhost:8888/bigDateApi/data/";
  var findBestSellerData = "findBestSellerData";
  var findBestSellerDataUrl = base+findBestSellerData;
  //hanyuu
  var findPopularity = "findPopularity";
  var findPopularityDataUrl = base+findPopularity;

  //   畅销书数据获取
  var pressData ;
  $.ajax({
    type : 'get',
    datatype : 'json',
      async:false,
      url:findBestSellerDataUrl,
      success:function (result){
        pressData = result.data
      }
  })

  var rankUl = $(".aside-left .top ul");

  var bookName = "";
  var pressName = "";
  var author = "";
  var ISBN = "";
  var pressDate = "";
  var pricing = "";
  var imageUrl = "";

  rankUl.each(function(index, item) {
    var len = item.children.length;
    for (let i = 0; i < len-1; i++) {
      bookName = pressData[i]["name"];
      pressName = pressData[i]['pbhouse_id'];
      author = pressData[i]["author_id"];
      ISBN = pressData[i]["isbn"];
      pressDate = pressData[i]["date"];
      pricing ="￥" + pressData[i]["price"];
      imageUrl = pressData[i]["img"];

      $(item.children[i])
        .find(".name")
        .text(bookName);
      $(item.children[i])
        .find(".company")
        .text(pressName);
      $(item.children[i])
        .find(".authors")
        .text(author);
      $(item.children[i])
        .find(".isbn")
        .text(ISBN);
      $(item.children[i])
        .find(".pub-date")
        .text(pressDate);
      $(item.children[i])
        .find(".pricing")
        .text(pricing);
      $(item.children[i])
        .find("img")
        .attr("src", imageUrl);
    }
  });


  //hanyuu   出版社热度获取
  var pbhouseData = "";
  $.ajax({
    type : 'get',
    datatype : 'json',
    async:false,
    url:findPopularityDataUrl,
    success:function (result){
      pbhouseData = result.data
    }
  })

  var hotUl = $(".left-bottom .bottom-in ul");

  var id = "";
  var shortName = "";
  var hot = "";

  hotUl.each(function(index, item) {
    var len =  item.children.length;
    for (var i = 0; i < len; i++) {
      id = pbhouseData[i]['id'];
      shortName = pbhouseData[i]['pbhouse_name'];
      hot = pbhouseData[i]['popular'];

      $(item.children[i])
          .find(".ranking")
          .text(id);
      $(item.children[i])
          .find(".short")
          .text(shortName);
      $(item.children[i])
          .find(".hot")
          .text(hot);
    }
  });


  // 复制第一个ul
  var parentWrap = $(".aside-left .top .over-wrap");
  var ulClone = $(".aside-left .top ul")
    .eq(0)
    .clone(true);
  parentWrap.append(ulClone);

	//   添加点击事件
  $(".aside-left .top").on('click', 'li', function(el) {
		var curItem = $(el.currentTarget);
		var bookName = curItem.find('.name').text().trim();
		var hasBook = false;
		var index = 0;
    console.log(bookName)
		for(var i = 0; i < bookData.length; i++) {
      console.log(bookData[i]["BookInformation"]["bookName"])
			if (bookData[i]["BookInformation"]["bookName"] === bookName) {
				index = i;
				hasBook = true;
				break;
			}
		}

		if (!hasBook) return false;

		var curHref = window.location.href;
		var str = curHref.indexOf("index.html");
		var newHref = curHref.substr(0, str) + "four.html?index=" + index;
		window.location.href = newHref;
	})

  //   获取行高
  var topSpan = $(".aside-left .top .book-rank span");
  var topSpanH = topSpan.height();
  topSpan.css("line-height", topSpanH + "px");

  var bottomSpan = $(".aside-left .bottom .book-rank span");
  var bottomSpanH = bottomSpan.height();
  bottomSpan.css("line-height", bottomSpanH + "px");
});

//   // 柱形折线图

var trendBar1 = echarts.init(document.getElementById("trendBar1"));
// 全国市场走势
var base = "http://localhost:8888/bigDateApi/data/";
var findMarketData = "findMarketData";
var findMarketDataUrl = base+findMarketData;
var data = {};

$.ajax({
  url:findMarketDataUrl,
  datatype:"json",
  sync:false,
  success:function (result){
    data = result.data
    console.log("折柱图",data)
    for (let i = 0; i < data['money'][0].length; i++) {
      if(data['money'][0][i] > 100){
        data['money'][0][i] = (20 +(Math.random()* 10)).toFixed(0);
      }
    }
    trendBar()
  }
})


function trendBar(){
  var optionBar = {
    grid: {
      top: 50,
      bottom: "20%"
    },
    legend: {
      data: ["销售码洋", "同比增长"],
      right: "5%",
      itemWidth: 18,
      itemHeight: 12,
      textStyle: {
        color: "#fff"
      }
    },
    xAxis: {
      data: [
        "1月",
        "2月",
        "3月",
        "4月",
        "5月",
        "6月",
        "7月",
        "8月",
        "9月",
        "10月",
        "11月",
        "12月"
      ],
      axisLine: {
        show: false,
        lineStyle: {
          color: "#07bffb"
        }
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        interval: 0
      }
    },
    yAxis: [
      {
        name: "码洋(/千万)",
        axisLine: {
          show: false,
          lineStyle: {
            color: "#07bffb"
          }
        },
        splitLine: {
          show: false
        },
        axisTick: {
          show: false
        },
        interval: 50,
        min: 0,
        max: 100,
        position: "left"
      },
      {
        name: "同比增长(%)",
        max: 100,
        min: 0,
        axisLabel: {
          formatter: "{value}"
        },
        axisLine: {
          show: false,
          lineStyle: {
            color: "#07bffb"
          }
        },
        splitLine: {
          show: false
        },
        axisTick: {
          show: false
        },
        position: "right"
      }
    ],
    series: [
      {
        name: "销售码洋",
        type: "bar",
        barWidth: "40%",
        barGap: 5,
        itemStyle: {
          normal: {
            color: new echarts.graphic.LinearGradient(
                0,
                0,
                0,
                1,
                [
                  {
                    offset: 0,
                    color: "#00fecc"
                  },
                  {
                    offset: 0.8,
                    color: "#2690cf"
                  }
                ],
                false
            )
          }
        },
        data: data.money[0]
      },
      {
        name: "同比增长",
        type: "line",
        itemStyle: {
          color: "#fff"
        },
        yAxisIndex: 1,
        data: data.growth[0]
      }
    ]
  };
  trendBar1.setOption(optionBar);
}


